package com.hefu.virtuallife.utils;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import com.dz.utlis.JavaUtils;

/**
 * creat_user: zhengzaihong
 * Email:1096877329@qq.com
 * creat_date: 2018/6/22
 * creat_time: 15:51
 * describe 获取或保存用户的信息
 **/
@SuppressWarnings("all")
public class SPUser {
    public static SPUser user;
    public static final String COOKIE = "Cookies";

    public static final String UID = "uid";
    private static final String MID = "mid";
    private static final String USER_TYPE = "user_type";
    private static final String TOKEN = "token";
    private static final String PASS = "PASS";
    private static final String USERNAME = "USERNAME";
    private static final String HEADICON = "HeadIcon";
    private static final String PHONE = "Phone";
    private static final String LAT = "LAT";
    private static final String LOG = "LOG";
    private static final String SEX = "SEX";

    private static final String VOICE = "VOICE";
    private static final String VIBRATOR = "Vibrator";


    private static final String USER_LEVEL = "USER_LEVEL";
    private static final String BALANCE = "balance";
    private static final String ALIPAY_ACCOUNT = "alipay_account";
    private static final String ALIPAY_USER_NAME = "alipay_user_name";
    private static final String TAOBAO_AUTHORIZED = "taobao_authorized";
    private static final String JD_AUTHORIZED = "jd_authorized";
    private static final String ANNUAL_RATE = "annual_rate";
    private static final String INTEGRAL = "integral";
    private static final String PRINCIPAL = "principal";
    private static final String EARNINGS_ACCUMULATED = "earnings_accumulated";
    private static final String EARNINGS_TODAY = "earnings_today";
    private static final String ONLINE_SP_ACCUMULATED_CONSUME = "online_sp_accumulated_consume";
    private static final String CONSUME_NUMBER = "consume_number";
    private static final String TTHB_STATUS = "tthb_status";
    private static final String TTHB_ALL_AMOUNT = "tthb_all_amount";
    private static final String TTHB_NOT_TRANS_TO_BALANCE = "tthb_not_trans_to_balance";
    private static final String FRIEND_CODE = "friend_code";
    private static final String SUM = "sum";
    private static final String MSUM = "msum";

    //xml 配置文件
    private static final String sp_configer = "user_info";


    private Context context;
    private SharedPreferences preferences;

    public static SPUser getUser(Application context) {
        if (user == null) {
            synchronized (SPUser.class) {
                if (user == null)
                    user = new SPUser(context);
            }
        }
        return user;
    }

    private SPUser(Context context) {
        this.context = context;
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
    }


    public SPUser setCookie(String cookie) {
        JavaUtils.outPrint("woshicookie: " + cookie);
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(COOKIE, cookie).commit();
        return this;
    }

    public String getCookie() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(COOKIE, "");
    }


    public SPUser setMSum(String msum) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(MSUM, msum).commit();
        return this;
    }

    public String getMSum() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(MSUM, "");
    }


    public SPUser setSum(String sum) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(SUM, sum).commit();
        return this;
    }

    public String getSum() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(SUM, "");
    }

    public SPUser setfriend_code(String friend_code) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(FRIEND_CODE, friend_code).commit();
        return this;
    }

    public String getfriend_code() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(FRIEND_CODE, "");
    }

    public SPUser settthb_not_trans_to_balance(String tthb_not_trans_to_balance) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(TTHB_NOT_TRANS_TO_BALANCE, tthb_not_trans_to_balance).commit();
        return this;
    }

    public String gettthb_not_trans_to_balance() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(TTHB_NOT_TRANS_TO_BALANCE, "");
    }


    public SPUser settthb_all_amount(String tthb_all_amount) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(TTHB_ALL_AMOUNT, tthb_all_amount).commit();
        return this;
    }

    public String gettthb_all_amount() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(TTHB_ALL_AMOUNT, "");
    }

    public SPUser settthb_status(String tthb_status) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(TTHB_STATUS, tthb_status).commit();
        return this;
    }

    public String gettthb_status() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(TTHB_STATUS, "");
    }

    public SPUser setconsume_number(String consume_number) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(CONSUME_NUMBER, consume_number).commit();
        return this;
    }

    public String getconsume_number() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(CONSUME_NUMBER, "");
    }

    public SPUser setonline_sp_accumulated_consume(String online_sp_accumulated_consume) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(ONLINE_SP_ACCUMULATED_CONSUME, online_sp_accumulated_consume).commit();
        return this;
    }

    public String getonline_sp_accumulated_consume() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(ONLINE_SP_ACCUMULATED_CONSUME, "");
    }

    public SPUser setearnings_today(String earnings_today) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(earnings_today, earnings_today).commit();
        return this;
    }

    public String getearnings_today() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(EARNINGS_TODAY, "");
    }


    public SPUser setearnings_accumulated(String earnings_accumulated) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(EARNINGS_ACCUMULATED, earnings_accumulated).commit();
        return this;
    }

    public String geearnings_accumulated() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(EARNINGS_ACCUMULATED, "");
    }


    public SPUser setprincipal(String principal) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(PRINCIPAL, principal).commit();
        return this;
    }

    public String geprincipal() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(PRINCIPAL, "");
    }


    public SPUser setintegral(String integral) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(INTEGRAL, integral).commit();
        return this;
    }

    public String getintegral() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(INTEGRAL, "");
    }


    public SPUser setannual_rate(String annual_rate) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(ANNUAL_RATE, annual_rate).commit();
        return this;
    }

    public String getannual_rate() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(ANNUAL_RATE, "");
    }


    public SPUser setjd_authorized(String jd_authorized) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(JD_AUTHORIZED, jd_authorized).commit();
        return this;
    }

    public String getjd_authorized() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(JD_AUTHORIZED, "");
    }


    public SPUser settaobao_authorized(String taobao_authorized) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(TAOBAO_AUTHORIZED, taobao_authorized).commit();
        return this;
    }

    public String gettaobao_authorized() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(TAOBAO_AUTHORIZED, "");
    }


    public SPUser setalipay_user_name(String alipay_user_name) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(ALIPAY_USER_NAME, alipay_user_name).commit();
        return this;
    }

    public String getalipay_user_name() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(ALIPAY_USER_NAME, "");
    }


    public SPUser setalipay_account(String alipay_account) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(ALIPAY_ACCOUNT, alipay_account).commit();
        return this;
    }

    public String getalipay_account() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(ALIPAY_ACCOUNT, "未绑定");
    }


    public SPUser setbalanceL(String balance) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(BALANCE, balance).commit();
        return this;
    }

    public String getbalance() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(BALANCE, "");
    }


    public SPUser setUSER_LEVEL(String USER_LEVEL) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(USER_LEVEL, USER_LEVEL).commit();
        return this;
    }

    public boolean getUSER_LEVEL() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getBoolean(USER_LEVEL, true);
    }

    public SPUser setVibrator(boolean flag) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putBoolean(VIBRATOR, flag).commit();
        return this;
    }

    public boolean getVibrator() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getBoolean(VIBRATOR, true);
    }


    public SPUser setVoice(boolean flag) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putBoolean(VOICE, flag).commit();
        return this;
    }

    public boolean getVoice() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getBoolean(VOICE, true);
    }


    public SPUser setLog(String log) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(LOG, log).commit();
        return this;
    }

    public String getLog() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(LOG, "");
    }

    public SPUser setSex(String sex) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(SEX, sex).commit();
        return this;
    }

    public String getSex() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(SEX, "");
    }


    public SPUser setLat(String lat) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(LAT, lat).commit();
        return this;
    }

    public String getLat() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(LAT, "");
    }

    public SPUser setHead(String head) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(HEADICON, head).commit();
        return this;
    }

    public String getHead() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(HEADICON, "");
    }


    public SPUser setPhone(String phone) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(PHONE, phone).commit();
        return this;
    }

    public String getPhone() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(PHONE, "");
    }


    public SPUser setPass(String pass) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(PASS, pass).commit();
        return this;
    }

    public String getPass() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(PASS, "");
    }


    public SPUser setUserName(String usr) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(USERNAME, usr).commit();
        return this;
    }

    public String getUserName() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(USERNAME, "");
    }


    public SPUser setUid(String uid) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(UID, uid).commit();
        return this;
    }

    public String getUid() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(UID, "");
    }


    public SPUser setMID(String mid) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(MID, mid).commit();
        return this;
    }

    public String getMID() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(MID, "");
    }


    public SPUser settoken(String token) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().putString(TOKEN, token).commit();
        return this;
    }

    public String gettoken() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        return preferences.getString(TOKEN, "");
    }


    public void remove(String key) {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().remove(key).commit();
    }

    public void clearUserInfo() {
        preferences = context.getSharedPreferences(sp_configer, Context.MODE_PRIVATE);
        preferences.edit().clear().commit();
    }

}
